<script type="text/javascript">
    (function () {
        function sendRequest(url, callback, postData) {
            var req = createXMLHTTPObject();
            if (!req) return;
            var method = (postData) ? "POST" : "GET";
            req.open(method, url, true);
            if (postData) {
                req.setRequestHeader && req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            }
            req.onreadystatechange = function () {
                if (req.readyState != 4) return;
                if (req.status != 200 && req.status != 304) {
                    return;
                }
                callback && callback(req);
            };
            if (req.readyState == 4) return;
            req.send(postData);
        }

        var XMLHttpFactories = [
            function () {
                if (typeof XDomainRequest != "undefined") {
                    // XDomainRequest for IE.
                    return new XDomainRequest();
                } else {
                    return new XMLHttpRequest();
                }
            },
            function () {
                return new ActiveXObject("Msxml2.XMLHTTP");
            },
            function () {
                return new ActiveXObject("Msxml3.XMLHTTP");
            },
            function () {
                return new ActiveXObject("Microsoft.XMLHTTP");
            }
        ];

        function createXMLHTTPObject() {
            var xmlhttp = false;
            for (var i = 0; i < XMLHttpFactories.length; i++) {
                try {
                    xmlhttp = XMLHttpFactories[i]();
                }
                catch (e) {
                    continue;
                }
                break;
            }
            return xmlhttp;
        }

        function submit(url, data) {
            var postData = {
                id: 5,
                type: 'fd_ex_qmyx_bd',
                content: JSON.stringify(data)
            };

            var dataStrArr = [];
            for (var key in postData) {
                if (key && postData.hasOwnProperty(key)) {
                    dataStrArr.push(key + '=' + encodeURIComponent(postData[key]));
                }
            }

            sendRequest(url, null, dataStrArr.join('&'));
        }

        var url = window.ENVIRONMENT_YUNKE.ex_monitor + '/api/msg';

        BJ_REPORT.init({
            id: 1,
            combo: 1,								// combo 是否合并上报， 0 关闭， 1 启动（默认）
            delay: 1000, 							// 当 combo= 1 可用，延迟多少毫秒，合并缓冲区中的上报
            submit: function (paramStr, error) {
                var data = {
                    ua: navigator.userAgent,
                    url: location.href,
                    msg: error
                };

                submit(url, data);
            }
        });
    })();
</script>